package cn.lg.soar.system.auth.model;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.database.base.entity.PathTreeEntity;
import cn.lg.soar.system.auth.entity.Post;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Set;

/**
 * 岗位(职位)
 * @author luguoxiang
 * @date 2021/9/11
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class PostDto extends PathTreeEntity {

    private static final long serialVersionUID = -4449119630824641083L;

    public final static BeanCopier<PostDto, Post> TO_ENTITY = BeanCopier.create(PostDto.class, Post.class);
    public final static BeanCopier<Post, PostDto> FROM_ENTITY = BeanCopier.create(Post.class, PostDto.class);

    @NotNull(message = "id不能为空", groups = {Update.class})
    @Min(value = 0, message = "id不能小于0", groups = {Update.class})
    @ApiModelProperty(value = "id")
    private Long id;

    @NotNull(message = "机构不能为空", groups = {Create.class})
    @ApiModelProperty(value = "岗位所属机构")
    private Long orgId;

    @NotBlank(message = "名称不能为空", groups = {Create.class})
    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "别名")
    private String alias;

    @ApiModelProperty(value = "描述")
    private String remark;

    @ApiModelProperty(value = "权限角色")
    private Set<Long> roleIds;

    @Override
    public Long primaryKey() {
        return this.id;
    }

    public PostDto() {
    }

    public PostDto(Post data) {
        FROM_ENTITY.copy(data, this);
    }

    public Post toPost() {
        return TO_ENTITY.convert(this);
    }
}
